/**
 *  @FileName: RegexMatches.java
 *  @Last Modified Date: CharlW
 *  @Description: start 和end 方法,对单词"cat"出现在输入字符串中出现次数进行计数
 */

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexMatches {
	private static final String REGEX = "\\bcat\\b";
	private static final String INPUT = "cat cat cat cattied cat";
	
	public static void main(String[] args) {
		Pattern p = Pattern.compile(REGEX);
		Matcher m = p.matcher(INPUT); // 获取 matcher 对象
		int count = 0;
		
		while (m.find()) {
			count++;
			System.out.println("Match number " + count);
			System.out.println("Start(): " + m.start());
			System.out.println("end():" + m.end());
		}
	}
}